*This file contains code to create Tables 2 (Panel B), 5, 6, 7, A1, A2, A3, A4, A5 and Figures 4, A5, A6, A7, A8

use "IDOCpanel1.dta", clear

g disburse_old = .
	replace disburse_old = 1 if lastfirst == "A" | lastfirst == "B"
	replace disburse_old = 2 if lastfirst == "C" | lastfirst == "D"
	replace disburse_old = 3 if lastfirst == "E" | lastfirst == "F" | lastfirst == "G"
	replace disburse_old = 4 if lastfirst == "H" | lastfirst == "I"
	replace disburse_old = 5 if lastfirst == "J" | lastfirst == "K" | lastfirst == "L"
	replace disburse_old = 6 if lastfirst == "M" | lastfirst == "N"
	replace disburse_old = 7 if lastfirst == "O" | lastfirst == "P" | lastfirst == "Q" | lastfirst == "R"
	replace disburse_old = 8 if lastfirst == "S"
	replace disburse_old = 9 if lastfirst == "T" | lastfirst == "U" | lastfirst == "V"
	replace disburse_old = 10 if lastfirst == "W" | lastfirst == "X" | lastfirst == "Y" | lastfirst == "Z"

g disburse_new = .
	replace disburse_new = 5 if lastfirst == "A" | lastfirst == "B"
	replace disburse_new = 7 if lastfirst == "C" | lastfirst == "D"
	replace disburse_new = 9 if lastfirst == "E" | lastfirst == "F" | lastfirst == "G"
	replace disburse_new = 11 if lastfirst == "H" | lastfirst == "I"
	replace disburse_new = 13 if lastfirst == "J" | lastfirst == "K" | lastfirst == "L"
	replace disburse_new = 15 if lastfirst == "M" | lastfirst == "N"
	replace disburse_new = 17 if lastfirst == "O" | lastfirst == "P" | lastfirst == "Q" | lastfirst == "R"
	replace disburse_new = 19 if lastfirst == "S"
	replace disburse_new = 21 if lastfirst == "T" | lastfirst == "U" | lastfirst == "V"
	replace disburse_new = 23 if lastfirst == "W" | lastfirst == "X" | lastfirst == "Y" | lastfirst == "Z"

g dom = day(commitdt_m)
g month = month(commitdt_m)
g dow = dow(commitdt_m)


****defining days since
g days_since_old = dom - disburse_old
g d1 = 30 - disburse_old + dom
	replace d1 = 31 - disburse_old + dom if month==1 | month==2 | month ==4 | month==6 | month==8 | month==9 |  month==11
	replace d1 = 28 - disburse_old + dom if month==3
replace days_since_old = d1 if days_since_old < 0
 	drop d1
	
g days_since_new = dom - disburse_new
g d1 = 30 - disburse_new + dom
	replace d1 = 31 - disburse_new + dom if month==1 | month==2 | month ==4 | month==6 | month==8 | month==9 |  month==11
	replace d1 = 28 - disburse_new + dom if month==3
replace days_since_new = d1 if days_since_new < 0
	drop d1

g since = days_since_new
		replace since = days_since_old if commityr < 2014
g week1 = since <7 
g week2 = since >6 & since <14
g week3 = since >13 & since <21
g week4 = week1 == 0 & week2 == 0 & week3 == 0

g since2=since^2

**new group of every 5 days
g daygroup1 = since <6
g daygroup2 = since >5 & since <11
g daygroup3 = since >10 & since <16
g daygroup4 = since >15 & since <21
g daygroup5 = daygroup1 == 0 & daygroup2 == 0 & daygroup3 == 0 & daygroup4==0

**new group of every 3 days
g threegroup1 = since <4
g threegroup2 = since >3 & since <7
g threegroup3 = since >6 & since <10
g threegroup4 = since >9 & since <13
g threegroup5 = since >12 & since <16
g threegroup6 = since >15 & since <19
g threegroup7 = since >18 & since <22
g threegroup8 = since >21 & since <25
g threegroup9 = since >24 & since <28
g threegroup10 = since >27 & since <32


**last name letter groups (from disbursement schedule)
g lettergroup=.
replace lettergroup=1 if lastfirst=="A" | lastfirst=="B"
replace lettergroup=2 if lastfirst=="C" | lastfirst=="D"
replace lettergroup=3 if lastfirst=="E" | lastfirst=="F" | lastfirst=="G"
replace lettergroup=4 if lastfirst=="H" | lastfirst=="I"
replace lettergroup=5 if lastfirst=="J" | lastfirst=="K" | lastfirst=="L"
replace lettergroup=6 if lastfirst=="M" | lastfirst=="N"
replace lettergroup=7 if lastfirst=="O" | lastfirst=="P" | lastfirst=="Q" | lastfirst=="R"
replace lettergroup=8 if lastfirst=="S" 
replace lettergroup=9 if lastfirst=="T" | lastfirst=="U" | lastfirst=="V"
replace lettergroup=10 if lastfirst=="W" | lastfirst=="X" | lastfirst=="Y" | lastfirst=="Z"

*Creating RD variables for Indiana policy analysis
g daytype_r1 = (dom == 1)
g daytype_r2_23 = (dom > 1 & dom < 24)
g daytype_r24_31 = (dom > 23)
g daytype_r = daytype_r1 ==1
		replace daytype_r = 2 if daytype_r2_23 == 1
		replace daytype_r = 3 if daytype_r24_31 == 1
		
g pre = ((commityr < 2014)| (commityr == 2014 & month < 2))
g post = (1-pre)
g run_var = commitdt_m - 19755
g run_var_post = post*run_var

sort commityr month
g commityr_month = (commityr*100) + month
egen month_id = group(commityr_month)
bys month_id: egen m2 = min(run_var)
drop month_id
rename m2 month_id

foreach var in run_var run_var_post{
g `var'_2 = `var'^2
g `var'_3 = `var'^3
}

**creating tables and figures (formatting)
loc REG_estout "substitute(_ \_ { $\left\{\text{ } }\right\}$) la collabels(none) posthead("") mlabels(none) prefoot("") postfoot("") varwidth(16) modelwidth(12) style(tex) starl(* .10 ** 0.05 *** 0.01)"


local weather prcp snwd snow tmax tmin awnd

scalar ti_any= "Crime"
scalar ti_drugs = "Drug Crimes"
scalar ti_alcohol = "Alcohol Crimes"
scalar ti_theft = "Theft"

label var any "Crime"
label var theft "Theft"
label var drugs "Drugs"
label var alcohol "Alcohol"

**************************
*******MAKE TABLES********
**************************

***Table 2: Indiana Summary Statistics (Panel B)
eststo clear
estpost sum any theft drugs alcohol, listwise  
estout using "INsumstats.tex", cells("mean (fmt(%6.3fc 3)) sd (fmt(%6.3fc 3)) N") `REG_estout' replace

	
***Table 5: Effect of SNAP Receipt on Crimes Committed After Issuance

*Panel A: Weeks Since Issuance
xi: areg any week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
sum any
scalar meanany = round(r(mean),0.001)
di meanany
estadd scalar ppmean= meanany
eststo l1
xi: areg theft week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
sum theft
scalar meantheft = round(r(mean),0.001)
di meantheft
estadd scalar ppmean= meantheft
eststo l2
xi: areg drugs week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
sum drugs
scalar meandrugs = round(r(mean),0.001)
di meandrugs
estadd scalar ppmean= meandrugs
eststo l3
xi: areg alcohol week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
sum alcohol
scalar meanalcohol = round(r(mean),0.001)
di meanalcohol
estadd scalar ppmean= meanalcohol
eststo l4
xi: areg dom_abuse week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
sum dom_abuse
scalar meandom_abuse = round(r(mean),0.001)
di meandom_abuse
estadd scalar ppmean= meandom_abuse
eststo l5
label var week2 "Second Week of Month"
label var week3 "Third Week of Month"
label var week4 "Fourth Week of Month"

estout l1 l2 l3 l4 using "IN_byweek.tex", cells(b(star fmt(3)) se(par fmt(3))) stats(N, fmt( 0) la("N")) keep(week*) `REG_estout' replace 

*Panel B: Nonlinear Effects
xi: areg any since since2 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
sum any
scalar meanany = round(r(mean),0.001)
di meanany
estadd scalar ppmean= meanany
eststo l1

xi: areg theft since since2 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
sum theft
scalar meantheft = round(r(mean),0.001)
di meantheft
estadd scalar ppmean= meantheft
eststo l2

xi: areg drugs since since2 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
sum drugs
scalar meandrugs = round(r(mean),0.001)
di meandrugs
estadd scalar ppmean= meandrugs
eststo l3

xi: areg alcohol since since2 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
sum alcohol
scalar meanalcohol = round(r(mean),0.001)
di meanalcohol
estadd scalar ppmean= meanalcohol
eststo l4

label var since "Days Since SNAP"
label var since2 "Days Since SNAP Squared"

estout l1 l2 l3 l4  using "IN_dayssince.tex", cells(b(star fmt(5)) se(par fmt(5))) stats(N, fmt(0) la("N")) keep(since*) `REG_estout' replace


***Table 6: Effect of Indiana SNAP Receipt by Every Three Days Since Issuance for Females
preserve
use "IDOCpanel1_female.dta", clear
g threegroup1 = since <4
g threegroup2 = since >3 & since <7
g threegroup3 = since >6 & since <10
g threegroup4 = since >9 & since <13
g threegroup5 = since >12 & since <16
g threegroup6 = since >15 & since <19
g threegroup7 = since >18 & since <22
g threegroup8 = since >21 & since <25
g threegroup9 = since >24 & since <28
g threegroup10 = since >27 & since <32

xi: areg any threegroup2-threegroup10 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l1
xi: areg theft threegroup2-threegroup10 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l2
xi: areg drugs threegroup2-threegroup10 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l3
xi: areg alcohol threegroup2-threegroup10 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l4


label var threegroup2 "3rd-5th of Month"
label var threegroup3 "6th-8th of Month"
label var threegroup4 "9th-11th of Month"
label var threegroup5 "12th-14th of Month"
label var threegroup6 "15th-17th of Month"
label var threegroup7 "18th-20th of Month"
label var threegroup8 "21st-23rd of Month"
label var threegroup9 "24th-26th of Month"
label var threegroup10 "27th-31st of Month"

estout l1 l2 l3 l4 using "IN_crimes_by3day_female.tex", cells(b(star fmt(3)) se(par fmt(3))) stats(N, fmt(0)) keep(threegroup*) `REG_estout' replace 
restore

***Table 7: Effect of Shifting SNAP Benefit Dates on Crime
set more off
preserve
drop daytype* post_day* runvarpost* runvar1 runvar2 runvar3
g daytype_r1 = (dom <6)
g daytype_r5_10 = (dom > 5 & dom < 11)
g daytype_r11_23 = (dom > 10 & dom < 24)
g daytype_r24_31 = (dom > 23)
g daytype_r = daytype_r1 ==1
		replace daytype_r = 2 if daytype_r5_10 == 1
		replace daytype_r = 3 if daytype_r11_23 == 1
		replace daytype_r = 4 if daytype_r24_31 == 1


g daytype_r2 = daytype_r5_10 
g daytype_r3 = daytype_r11_23 
g daytype_r4 = daytype_r24_31 

forvalues d = 1/4{
g post_day`d' = post*daytype_r`d'
g runvar`d' =  run_var*daytype_r`d'
g runvarpost`d' = runvar`d'*post
}
foreach t in any drugs alcohol theft {
eststo basect_t`t': xi: areg `t' post run_var run_var_post `weather' i.commityr i.dow i.dom, vce(cluster lastfirst) absorb(lastfirst)
sum `t' if post == 0
scalar mean`t' = round(r(mean),0.001)
di mean`t'
estadd scalar ppmean= mean`t'

eststo mainct_t`t': xi: areg `t' post run_var run_var_post `weather' i.commityr i.dow i.dom if abs(run_var)<`bw_`t'', vce(cluster lastfirst) absorb(lastfirst)
sum `t' if post == 0 & run_var>-`bw_`t''
scalar mean`t' = round(r(mean),0.001)
di mean`t'
estadd scalar ppmean= mean`t'

forvalues r = 1/4{
eststo rangect`r'_t`t': xi: areg `t' post run_var run_var_post `weather' i.commityr i.dow i.dom if abs(run_var)<`bw_`t'' & daytype_r == `r', vce(cluster lastfirst) absorb(lastfirst)
sum `t' if post == 0 & daytype_r == `r' & run_var>-`bw_`t''
scalar mean`t'_r`r' = round(r(mean),0.001)
di mean`t'_r`r'
estadd scalar ppmean= mean`t'_r`r'
}

}

	estout *tany* using "t4_anyIN.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post) varlabels(post "SNAP Staggered")
	estout *tdrugs using "t4_drugsIN.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post) varlabels(post "SNAP Staggered")
	estout *ttheft* using "t4_theftIN.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post) varlabels(post "SNAP Staggered")
	estout *talcohol* using "t4_alcoholIN.tex", replace c(b(star fmt(4)) se(par fmt(4))) `REG_estout' stats(ppmean N, fmt(3 0) la("Pre-Period Mean" "N")) keep(post) varlabels(post "SNAP Staggered")
	eststo clear
	restore
	
	
***Table A1: Summary Statistics by Letter Group
eststo clear
estpost tabstat any theft drugs alcohol, by(lettergroup) listwise statistics(mean) nototal column(stat)
label var any "Crime"
label var theft "Theft"
label var drugs "Drugs"
label var alcohol "Alcohol"
label var lettergroup "Letter Group"
estout using "INsumstats_bylettergroup.tex", unstack cells("mean (fmt(%6.2fc 2)) ") eqlabels(none) `REG_estout' replace


*Table A2: crimes by three day group
xi: areg any threegroup2-threegroup10 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l1
xi: areg theft threegroup2-threegroup10 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l2
xi: areg drugs threegroup2-threegroup10 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l3
xi: areg alcohol threegroup2-threegroup10 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l4

label var threegroup2 "3rd-5th of Month"
label var threegroup3 "6th-8th of Month"
label var threegroup4 "9th-11th of Month"
label var threegroup5 "12th-14th of Month"
label var threegroup6 "15th-17th of Month"
label var threegroup7 "18th-20th of Month"
label var threegroup8 "21st-23rd of Month"
label var threegroup9 "24th-26th of Month"
label var threegroup10 "27th-31st of Month"

estout l1 l2 l3 l4 using "IN_crimes_by3day.tex", cells(b(star fmt(3)) se(par fmt(3))) stats(N, fmt(0)) keep(threegroup*) `REG_estout' replace 


***Table A3: Effect of Indiana SNAP Receipt by County
preserve
 use "IDOCpanel1_county.dta", clear
 

xi: areg any week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l1
xi: areg theft week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l2
xi: areg drugs week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l3
xi: areg alcohol week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l4

label var week2 "Second Week of Month"
label var week3 "Third Week of Month"
label var week4 "Fourth Week of Month"

estout l1 l2 l3 l4 using "IN_detailcrimes_byweek_county.tex", cells(b(star fmt(3)) se(par fmt(3))) stats(N, fmt(0)) keep(week*) `REG_estout' replace 


xi: areg any week2-week4 i.commityr i.month i.dom i.dow if samplehisnap==1, absorb(lastfirst) vce(cluster lastfirst)
eststo l1
xi: areg theft week2-week4 i.commityr i.month i.dom i.dow if samplehisnap==1, absorb(lastfirst) vce(cluster lastfirst)
eststo l2
xi: areg drugs week2-week4 i.commityr i.month i.dom i.dow if samplehisnap==1, absorb(lastfirst) vce(cluster lastfirst)
eststo l3
xi: areg alcohol week2-week4 i.commityr i.month i.dom i.dow if samplehisnap==1, absorb(lastfirst) vce(cluster lastfirst)
eststo l4

label var week2 "Second Week of Month"
label var week3 "Third Week of Month"
label var week4 "Fourth Week of Month"

estout l1 l2 l3 l4  using "IN_detailcrimes_byweek_county_highsnap.tex", cells(b(star fmt(3)) se(par fmt(3))) stats(N, fmt(0)) keep(week*) `REG_estout' replace 


xi: areg any week2-week4 i.commityr i.month i.dom i.dow if samplelosnap==1, absorb(lastfirst) vce(cluster lastfirst)
eststo l1
xi: areg theft week2-week4 i.commityr i.month i.dom i.dow if samplelosnap==1, absorb(lastfirst) vce(cluster lastfirst)
eststo l2
xi: areg drugs week2-week4 i.commityr i.month i.dom i.dow if samplelosnap==1, absorb(lastfirst) vce(cluster lastfirst)
eststo l3
xi: areg alcohol week2-week4 i.commityr i.month i.dom i.dow if samplelosnap==1, absorb(lastfirst) vce(cluster lastfirst)
eststo l4

label var week2 "Second Week of Month"
label var week3 "Third Week of Month"
label var week4 "Fourth Week of Month"

estout l1 l2 l3 l4  using "IN_detailcrimes_byweek_county_lowsnap.tex", cells(b(star fmt(3)) se(par fmt(3))) stats(N, fmt(0)) keep(week*) `REG_estout' replace 

restore

***Table A4: Effect of Indiana SNAP Receipt on Crime by Race, Ethnicity, and Gender
 *Panel A. White
 preserve
 use "IDOCpanel1_white.dta", clear

xi: areg any week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l1
xi: areg theft week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l2
xi: areg drugs week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l3
xi: areg alcohol week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l4

label var week2 "Second Week of Month"
label var week3 "Third Week of Month"
label var week4 "Fourth Week of Month"

estout l1 l2 l3 l4  using "IN_detailcrimes_byweek_white.tex", cells(b(star fmt(3)) se(par fmt(3))) stats(N, fmt(0)) keep(week*) `REG_estout' replace 
restore

*Panel B. Black
 preserve
 use "IDOCpanel1_black.dta", clear
 
xi: areg any week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l1
xi: areg theft week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l2
xi: areg drugs week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l3
xi: areg alcohol week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l4

label var week2 "Second Week of Month"
label var week3 "Third Week of Month"
label var week4 "Fourth Week of Month"

estout l1 l2 l3 l4  using "IN_detailcrimes_byweek_black.tex", cells(b(star fmt(3)) se(par fmt(3))) stats(N, fmt(0)) keep(week*) `REG_estout' replace 
restore

*Panel C. Hispanic
 preserve
 use "IDOCpanel1_hispanic.dta", clear
 
xi: areg any week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l1
xi: areg theft week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l2
xi: areg drugs week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l3
xi: areg alcohol week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l4
xi: areg dom_abuse week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l5
label var week2 "Second Week of Month"
label var week3 "Third Week of Month"
label var week4 "Fourth Week of Month"

estout l1 l2 l3 l4  using "IN_detailcrimes_byweek_hispanic.tex", cells(b(star fmt(3)) se(par fmt(3))) stats(N, fmt(0)) keep(week*) `REG_estout' replace 
restore

*Panel D. Female
 preserve
 use "IDOCpanel1_female.dta", clear
 
 
xi: areg any week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l1
xi: areg theft week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l2
xi: areg drugs week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l3
xi: areg alcohol week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
eststo l4

label var week2 "Second Week of Month"
label var week3 "Third Week of Month"
label var week4 "Fourth Week of Month"

estout l1 l2 l3 l4  using "IN_detailcrimes_byweek_female.tex", cells(b(star fmt(3)) se(par fmt(3))) stats(N, fmt(0)) keep(week*) `REG_estout' replace 
restore


***Table A5: Effect of Indiana SNAP Receipt on Crime by Age Group
 preserve
 use "IDOCpanel1_ages.dta", clear
 
*Note: agegroups: 1=<18, 2=18-24, 3=25-30, 4=30-35, 5=35-40, 6=>40
forvalues i=1(1)6 {
xi: areg any week2-week4 i.commityr i.month i.dom i.dow if agegroup==`i', absorb(lastfirst) vce(cluster lastfirst)
eststo l1
xi: areg theft week2-week4 i.commityr i.month i.dom i.dow if agegroup==`i', absorb(lastfirst) vce(cluster lastfirst)
eststo l2
xi: areg drugs week2-week4 i.commityr i.month i.dom i.dow if agegroup==`i', absorb(lastfirst) vce(cluster lastfirst)
eststo l3
xi: areg alcohol week2-week4 i.commityr i.month i.dom i.dow if agegroup==`i', absorb(lastfirst) vce(cluster lastfirst)
eststo l4

label var week2 "Second Week of Month"
label var week3 "Third Week of Month"
label var week4 "Fourth Week of Month"

estout l1 l2 l3 l4  using "IN_detailcrimes_byweek_agegroup`i'.tex", cells(b(star fmt(3)) se(par fmt(3))) stats(N, fmt(0)) keep(week*) `REG_estout' replace 
}
	restore


**********************
*****MAKE FIGURES*****
**********************
***Figure 4: Averages Crimes Committed: Benefit vs. Calendar Month
foreach t in any theft drugs alcoho { 		
xi: reg `t' i.commityr i.month, r
predict `t'_resid_yrmon, r
		
bys since: egen mean_`t'_day = mean(`t'_resid_yrmon)
bys dom: egen mean_`t'_dom= mean(`t'_resid_yrmon)
#delimit ;
twoway (lpoly mean_`t'_day since, lp(dash)) (lpoly mean_`t'_dom dom), ti(`=ti_`t'' by Day of Month, margin(b=2)) legend(label(1 "Benefits Month (Days Since)") label(2 "Calendar Month")) 
	yti("Residualized Means", margin(r = 2)) xti("Day of Month", margin(t = 2 b = 2)) graphregion(color(white) lc(white)) 
;
#delimit cr
graph export "dom_`t'_Indiana.png", replace
}



***Figure A5: Estimates of SNAP Receipt on Crime, by Crime Type
	set more off
	preserve
foreach crime in any theft drugs alcohol {
xi: areg `crime' week2-week4 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
forvalues w = 2/4{
g b_wk_`crime'`w' = _b[week`w']
g se_wk_`crime'`w' = _se[week`w']
}
}

keep b_wk* se_wk*

duplicates drop
g id = 1

#delimit ;
reshape long 
b_wk_any se_wk_any
b_wk_drugs se_wk_drugs
b_wk_theft se_wk_theft 
b_wk_alcohol se_wk_alcohol

, i(id) j(wk)
;
#delimit cr

foreach t in any theft drugs alcohol {
g ul_`t' = b_wk_`t' + (1.96*se_wk_`t')
g ll_`t' = b_wk_`t' - (1.96*se_wk_`t')
}

global graphstuff graphregion(color(white) lc(white)) yline(0, lcolor(black))  legend(label(1 "Coefficient") label(2 "95% CI")) xtitle("Weeks from Disbursement", margin(t=2 b=2)) ytitle("Estimated effect", margin(l=2 r=2))
twoway (scatter b_wk_any wk, connect(l)) (rcap ll_any ul_any wk), $graphstuff ti("Disbursement Effects on Crime")
graph export "week_any.png", replace

twoway (scatter b_wk_drugs wk, connect(l)) (rcap ll_drugs ul_drugs wk), $graphstuff ti("Disbursement Effects on Drug Crimes")
graph export "week_drugs.png", replace

twoway (scatter b_wk_alcohol wk, connect(l)) (rcap ll_alcohol ul_alcohol wk), $graphstuff ti("Disbursement Effects on Alcohol Crimes")
graph export "week_alcohol.png", replace

twoway (scatter b_wk_theft wk, connect(l)) (rcap ll_theft ul_theft wk), $graphstuff ti("Disbursement Effects on Theft")
graph export "week_theft.png", replace
restore


***Figure A6: Estimates of SNAP Receipt on Crime by Crime Type, Every Three Days
preserve
foreach crime in any drugs theft alcohol {
xi: areg `crime' threegroup2-threegroup10 i.commityr i.month i.dom i.dow, absorb(lastfirst) vce(cluster lastfirst)
forvalues w = 2/10{
g b_wk_`crime'`w' = _b[threegroup`w']
g se_wk_`crime'`w' = _se[threegroup`w']
}
}

keep b_wk* se_wk*

duplicates drop
g id = 1

#delimit ;
reshape long 
b_wk_any se_wk_any
b_wk_drugs se_wk_drugs
b_wk_theft se_wk_theft 
b_wk_alcohol se_wk_alcohol

, i(id) j(wk)
;
#delimit cr

foreach t in any theft drugs alcohol {
g ul_`t' = b_wk_`t' + (1.96*se_wk_`t')
g ll_`t' = b_wk_`t' - (1.96*se_wk_`t')
}

global graphstuff graphregion(color(white) lc(white)) yline(0, lcolor(black))  legend(label(1 "Coefficient") label(2 "95% CI")) xtitle("Weeks from Disbursement", margin(t=2 b=2)) ytitle("Estimated effect", margin(l=2 r=2))

gen ta="0"
replace ta="4-6" if wk==2
replace ta="7-9" if wk==3
replace ta="10-12" if wk==4
replace ta="13-15" if wk==5
replace ta="16-18" if wk==6
replace ta="19-21" if wk==7
replace ta="22-24" if wk==8
replace ta="25-27" if wk==9
replace ta="28-31" if wk==10
labmask wk, values(ta)
global graphstuff graphregion(color(white) lc(white)) yline(0, lcolor(black))  legend(label(1 "Coefficient") label(2 "95% CI")) xtitle("Days from Disbursement", margin(t=2 b=2)) ytitle("Estimated effect", margin(l=2 r=2))

twoway (scatter b_wk_any wk, connect(l)) (rcap ll_any ul_any wk), $graphstuff ti("Disbursement Effects on Crime") xlabel(2(1)10, valuelabel)
graph export "week_any_threeday.png", replace

twoway (scatter b_wk_drugs wk, connect(l)) (rcap ll_drugs ul_drugs wk), $graphstuff ti("Disbursement Effects on Drug Crimes") xlabel(2(1)10, valuelabel)
graph export "week_drugs_threeday.png", replace

twoway (scatter b_wk_alcohol wk, connect(l)) (rcap ll_alcohol ul_alcohol wk), $graphstuff ti("Disbursement Effects on Alcohol Crimes") xlabel(2(1)10, valuelabel)
graph export "week_alcohol_threeday.png", replace

twoway (scatter b_wk_theft wk, connect(l)) (rcap ll_theft ul_theft wk), $graphstuff ti("Disbursement Effects on Theft") xlabel(2(1)10, valuelabel)
graph export "week_theft_threeday.png", replace
restore 


*Figure A7: Effect of SNAP Disbursement Change on Crime, Optimal BW
local bw_any 98.7
local bw_theft 120
local bw_drugs 120
local bw_alcohol 120
	*note: due to sentencing reform in Indiana in June 2014, we limit the bandwidth to 120 days on either side

foreach t in any drugs theft alcohol { 	
preserve
keep if abs(run_var)<`bw_`t''
xi: areg `t' `weather' if abs(run_var)<`bw_`t'', r absorb(lastfirst)
predict `t'_resid_mon_ct, r
bys month_id: egen mean_`t'_monthct = mean(`t'_resid_mon_ct) 

#delimit ;
twoway (lfitci `t'_resid_mon_ct run_var if run_var <0) (lfitci `t'_resid_mon_ct run_var if run_var >-1) 
(scatter mean_`t'_monthct month_id if month_id <0) (scatter mean_`t'_monthct month_id if month_id >-1), ti(`=ti_`t'')  
xline(0) legend(label(4 "pre: monthly means") label(5 "post: monthly means") order(1 2 4 5))  xlabel( 0 "Feb 2014" -90 "Nov 2013" 90 "May 2014") 
xti(date, margin(t = 2 b = 2)) t1title("SNAP on 1st-10th                               SNAP on 5-23", margin(t=3)) yti("residualized monthly mean", margin(r=2)) graphregion(color(white) lc(white))
;
graph export "IN_ct_rdd_`t'_optimal.png", replace;
#delimit cr
restore
}

***Figure A8: Effect of SNAP Disbursement Change on Crime, Full BW
foreach t in any drugs theft alcohol { 		
xi: areg `t' i.month, r absorb(lastfirst)
predict `t'_resid_mon_ct, r
bys month_id: egen mean_`t'_monthct = mean(`t'_resid_mon_ct) 

#delimit ;
twoway (lfitci `t'_resid_mon_ct run_var if month_id <0) (lfitci `t'_resid_mon_ct run_var if month_id >-1) 
(scatter mean_`t'_monthct month_id if month_id <0) (scatter mean_`t'_monthct month_id if month_id >-1), ti(`=ti_`t'')  
xline(-.5) legend(label(4 "pre: monthly means") label(5 "post: monthly means") order(1 2 4 5)) xlabel( 0 "Feb 2014" -365 "Feb 2013" 365 "Feb 2015" -730 "Feb 2012" 730 "Feb 2016") 
xti(date, margin(t = 2 b = 2)) t1title("SNAP on 1st-10th                               SNAP on 5-23", margin(t=3)) yti("residualized monthly mean", margin(r=2)) graphregion(color(white) lc(white))
;
graph export "IN_ct_rdd_`t'.png", replace;
#delimit cr
}



	



